
const BOX=document.querySelector(".BODY")
BOX.onclick=function(eve){
    const e=eve||window.event
    const target=e.target||e.srcElement
    var num=$(".BODY .shop .cal .cont").html()
    if(target.getAttribute("class")==="plus"){ 
        if(num>=5){
            return
        }else{
            num++
            target.parentNode.previousElementSibling.innerHTML=num
        }  
    }
    if(target.getAttribute("class")==="unplus"){ 
        if(num<=1){
            return
        }else{
            num--
            target.parentNode.previousElementSibling.innerHTML=num
        }  
    }
}
var urls=location.search.split("?")[1]
var xqygoods = decodeURI(urls)
$.ajax({
url: 'http://localhost:3000/json/xqygoods.json',
success: (res) => {
    var res=JSON.parse(res)
    $(".box").remove()
    let str=""
    for (var i = 0; i < res.length; i++) {
        if (xqygoods === res[i].proName) {
            str+=`
            <div class="box">
            <div class="show">
                <img src="${res[i].img_show[0]}" alt="">
                <div class="mask"></div>
            </div>
            <div class="enlarge"></div>
            <div class="list">
                <p class="active">
                    <img src="${res[i].img[0]}" data-show="${res[i].img_show[0]}" data-big="${res[i].img_big[0]}" alt="">
                </p>`

            for(var j=1;j<res[i].img.length;j++){
                str+=`
                <p>
                    <img src="${res[i].img[j]}" data-show="${res[i].img_show[j]}" data-big="${res[i].img_big[j]}" alt="">
                </p>
                `
            }
            str+=`</div>
        </div>
        <div class="box2">
            <div class="title">
                <p>${res[i].proName}</p>
                <p>${res[i].proId}</p>
            </div>
            <div class="contentx">
                <p><span>品牌</span><a href="#"><img src="${res[i].brand_img}" alt=""></a></p>
                <p><span>价格</span><span>￥</span><span>${res[i].price}</span></p>
                <p><span>活动</span><span>赠:2021.12.14-12.29 在丝芙兰官网、APP及小程序，全场任意购买实付满1588 即可获赠价值899元的丝芙兰圣诞限定16寸彩绘旅行箱一个（限量50个，数量有限，赠完即止，不与其他活动同享，详情请以购物车结算页面为准）</span></p>
                <div class="cal">
                <div>
                    <p class="cont">1</p>
                    <p>
                        <span class="plus">+</span>
                        <span class="unplus">-</span>
                    </p>
                </div>
                <p>(每人限购5件)</p>
                <p>加入购物车</p>
            </div>
            </div>
        </div>
            `
        }
    }
    $(".BODY .shop").html(str)
}
})

